import os

from config import BUILD_SCRIPT_SUFFIX, BUILD_SCRIPT_FILE


def _CollectAllFile(libPath):
    allFile = []
    for root, dirs, files in os.walk(libPath):
        for fileName in files:
            allFile.append(fileName)

    return allFile

def _DistinguishBuildScript(libFiles):
    buildScript = [] # 项目可能不只一种构建方式
    for file in libFiles:
        for bs, suffixs in BUILD_SCRIPT_SUFFIX.items():
            for suffix in suffixs:
                if file.endswith(suffix):
                    if bs not in buildScript:
                        buildScript.append(bs)
                        break
        for bs, fileNames in BUILD_SCRIPT_FILE.items():
            for fileName in fileNames:
                if fileName == file:
                    if bs not in buildScript:
                        buildScript.append(bs)
                        break
    return buildScript

def BuildScripts(libPath):
    allFile = _CollectAllFile(libPath)
    buildScript = _DistinguishBuildScript(allFile)
    return buildScript

if __name__ == "__main__":
    libPath = '/home/ohos/openHarmony/cocos_libs/pvmp3decoder-main/'
    buildScript = BuildScripts(libPath)
    print(buildScript)